package com.virtualtrainer_01.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import com.virtualtrainer_01.R;
import com.virtualtrainer_01.dao.ExerciseDB;
import com.virtualtrainer_01.model.Exercise;

public class Description extends Activity {

	private TextView exerciseName;
	private TextView exerciseDescription;
	private ImageView exercisePicture;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.exercise_description);
		getActionBar().setDisplayHomeAsUpEnabled(true);

		exerciseName = (TextView) findViewById(R.id.tv_exerciseName);
		exerciseDescription = (TextView) findViewById(R.id.tv_exerciseDescription);
		exercisePicture = (ImageView) findViewById(R.id.iv_exercisePicture);
		onActivityResult(1, 1, this.getIntent());
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		finish();
		return super.onOptionsItemSelected(item);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (data.getExtras().containsKey("cheia"))
			exerciseName.setText(data.getStringExtra("cheia"));

		Exercise e;
		ExerciseDB edb = new ExerciseDB(this);
		edb.open();
		e = edb.getExercise(exerciseName.getText().toString());
		edb.close();
		exerciseDescription.setText("Description: " + e.getDescription());
		// Toast.makeText(this, data.getStringExtra("cheia"),
		// Toast.LENGTH_LONG).show();
	}

}
